package com.itboye.sunsun.adapter;

import java.util.List;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.LunTanHomePageBean.LunTanItemBean;
import com.itboye.sunsun.constants.NetPublicConstant;
import com.itboye.sunsun.utils.XImageLoader;
import com.itboye.sunsunhome.R;

public class JingHuaTieAdapter extends BaseAdapter {

	List<LunTanItemBean> dataList;
	Activity activity;

	public JingHuaTieAdapter(List<LunTanItemBean> dataList, Activity activity) {
		// TODO Auto-generated constructor stub
		this.dataList = dataList;
		this.activity = activity;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
//			convertView = LayoutInflater.from(App.ctx).inflate(
//					R.layout.item_lun_detail, null);
			
			
			convertView = LayoutInflater.from(App.ctx).inflate(
					R.layout.item_order_name_picture_count, null);
			holder = new ViewHolder();
			holder.content = (TextView) convertView.findViewById(R.id.content);
			holder.time = (TextView) convertView.findViewById(R.id.time);
			holder.commont = (TextView) convertView.findViewById(R.id.commont);

			holder.iv1 = (ImageView) convertView.findViewById(R.id.iv1);

			holder.luntanjing = (ImageView) convertView.findViewById(R.id.luntanjing);
//			
			holder.imgsContainer = (ViewGroup) convertView
					.findViewById(R.id.imgsContainer);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		LunTanItemBean bean = dataList.get(position);

//		if (bean.getUserInfo() == null) {
//			holder.name.setText(bean.getAuthor());
//		} else {
//			holder.name.setText(bean.getUserInfo().getNickname());
//		}

		
		 if (dataList.get(position).getDigest().equals("1")) {
			holder.luntanjing.setVisibility(View.VISIBLE);
		}
//
//		if (dataList.get(position).getStick().equals("0")) {
//			holder.zhiding.setVisibility(View.INVISIBLE);
//		} else {
//			holder.zhiding.setVisibility(View.VISIBLE);
//		}
		// Toast.makeText(App.ctx, dataList.get(position).getDigest(),
		// 0).show();

		holder.content.setText(bean.getSubject());

		holder.time.setText(bean.getDatelineShow());
//		holder.zan.setText(bean.getLikes());
		holder.commont.setText(bean.getReplies());

		List<String> imgs = bean.getImg();
		holder.iv1.setImageBitmap(null);
//		holder.iv2.setImageBitmap(null);
//		holder.iv3.setImageBitmap(null);
		holder.iv1.setTag(position);
//		holder.iv2.setTag(position);
//		holder.iv3.setTag(position);

		holder.imgsContainer.setVisibility(View.VISIBLE);
		System.out.println("图片路径"+imgs);
		if(imgs!=null){
		if (imgs.size() > 0) {
				XImageLoader.load(NetPublicConstant.IMAGE_URL + imgs.get(0),
						holder.iv1);
		}else{
				Bitmap bitmap = BitmapFactory.decodeResource(
						activity.getResources(), R.drawable.moren_png);
				holder.iv1.setImageBitmap(bitmap);
		}
		}
//
//		holder.head.setImageBitmap(null);
//		try {
//			if (bean.getUserInfo().getHead() == ""
//					|| bean.getUserInfo().getHead() == null) {
//				Bitmap bitmap = BitmapFactory.decodeResource(
//						activity.getResources(), R.drawable.defaultimage);
//
//				holder.head.setImageBitmap(bitmap);
//			} else {
//				holder.head.setImageBitmap(null);
//				if (!bean.getUserInfo().getHead().startsWith("http")) {
//					XImageLoader.load(NetPublicConstant.IMAGE_URL
//							+ bean.getUserInfo().getHead(), holder.head);
//				} else {
//					XImageLoader
//							.load(bean.getUserInfo().getHead(), holder.head);
//				}
//			}
//		} catch (Exception e) {
//		}
		return convertView;
	}

	class ViewHolder {

//		TextView name;
		TextView content;
		TextView time;
//		TextView zan;
		TextView commont;
//		ImageView head;
//		ImageView zhiding;
		ImageView iv1;
//		ImageView iv2;
//		ImageView iv3;
		ImageView luntanjing;

		ViewGroup imgsContainer;
	}
}
